library(tidyverse)
library(GGally)
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
df <- read_csv("../data/example.csv")
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## `Variable Name` = col_character(),
## `Model A` = col_double(),
## `Model B` = col_double(),
## `Model C` = col_double(),
## `Model D` = col_double(),
## `Model E` = col_double(),
## `Model F` = col_double()
## )
tidy_df <- df %>% pivot_longer(-`Variable Name`, names_to = "model", values_to = "percent")
g <- ggplot(tidy_df, aes(x = model, y = percent, group = `Variable Name`)) +
geom_line()
g

g + geom_text(data = df[,1:2], aes(x = .8, y = `Model A`, label = `Variable Name`))

plotly::ggplotly(g)
# Back to original data frame
ggparcoord(df[-1], scale = "globalminmax")

df$group <- c(rep("top 6", 6), rep("other", 37))
g <- ggparcoord(df, columns = 2:7, scale = "globalminmax",
groupColumn = 8, alphaLines = .5) +
scale_color_manual(values = c('#d95f02','#1b9e77'),
guide = guide_legend(reverse = TRUE)) +
scale_y_continuous(breaks = seq(0, 100, 10))
ggplotly(g)
ggparcoord(df, columns = 2:7, scale="globalminmax",
groupColumn = 8, alphaLines = .5) +
scale_color_manual(values = c('#d95f02','#1b9e77'),
guide = guide_legend(reverse = TRUE)) +
scale_y_continuous(breaks = seq(0, 100, 10))

library(palmerpenguins)
str(penguins)
## tibble [344 × 8] (S3: tbl_df/tbl/data.frame)
## $ species : Factor w/ 3 levels "Adelie","Chinstrap",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ island : Factor w/ 3 levels "Biscoe","Dream",..: 3 3 3 3 3 3 3 3 3 3 ...
## $ bill_length_mm : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...
## $ bill_depth_mm : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...
## $ flipper_length_mm: int [1:344] 181 186 195 NA 193 190 181 195 193 190 ...
## $ body_mass_g : int [1:344] 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...
## $ sex : Factor w/ 2 levels "female","male": 2 1 1 NA 1 2 1 2 NA NA ...
## $ year : int [1:344] 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...
ggparcoord(penguins)

ggparcoord(penguins, columns = 3:6)

ggparcoord(penguins, columns = 3:6, alphaLines = .3)

ggparcoord(penguins, columns = 3:6, alphaLines = .3, groupColumn = 1)

ggparcoord(penguins, columns = 3:6, alphaLines = .3, groupColumn = 1,
splineFactor = 10)

colors3 <- c("orange","cyan","blue")
lattice::splom(penguins[,3:6], cex = .5, pch = 16,
col = colors3[penguins$species],
key = list(space="bottom",
points=list(pch = 16, col=colors3),
text=list(levels(penguins$species))))
